From 5bb16295d0ef25d6ee3580c5a74184584ad1ef4a Mon Sep 17 00:00:00 2001 From: "akw27@boulderdash.cl.cam.ac.uk" Date: Mon, 19 May 2003 19:26:22 +0000 Subject: [PATCH] bitkeeper revision 1.245 (3ec92fdez1HafjDKzTvVNtSF_Pa4_g) net_headers.h: new file kernel.c: remove in-file net header declarations, put them in net_headers.h --- .rootkeys | 1 + xen/common/kernel.c | 59 ++++----------- xen/include/xeno/net_headers.h | 128 +++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 47 deletions(-) create mode 100644 xen/include/xeno/net_headers.h diff --git a/.rootkeys b/.rootkeys index 5094916c1f..de42d5d437 100644 --- a/.rootkeys +++ b/.rootkeys @@ -430,6 +430,7 @@ 3ddb79c1gs2VbLbQlw0dcDUXYIepDA xen/include/xeno/mm.h 3ddb79c13p9iHn1XAp0IS1qvj4yDsg xen/include/xeno/module.h 3ddb79c1ieLZfGSFwfvvSQ2NK1BMSg xen/include/xeno/multiboot.h +3ec92e46saEJq7v1vgEJD3HZSufSBg xen/include/xeno/net_headers.h 3ddb79c0CLfAlJLg1ohdPD-Jjn-jxg xen/include/xeno/netdevice.h 3e4540ccaugeWGdOuphJKj6WFw1jkw xen/include/xeno/notifier.h 3ddb79c2Fg44_PBPVxHSC0gTOMq4Ow xen/include/xeno/pci.h diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 3c92324ca1..5e1e2fc194 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -18,6 +18,7 @@ #include #include #include +#include static int xpos, ypos; static volatile unsigned char *video; @@ -467,42 +468,6 @@ unsigned short compute_cksum(unsigned short *buf, int count) extern int netif_rx(struct sk_buff *); -typedef struct my_udphdr { - __u16 source; - __u16 dest; - __u16 len; - __u16 check; -} my_udphdr_t; - - -typedef struct my_iphdr { -#if defined(__LITTLE_ENDIAN_BITFIELD) - __u8 ihl:4, - version:4; -#elif defined (__BIG_ENDIAN_BITFIELD) - __u8 version:4, - ihl:4; -#else -#error "Please fix " -#endif - __u8 tos; - __u16 tot_len; - __u16 id; - __u16 frag_off; - __u8 ttl; - __u8 protocol; - __u16 check; - __u32 saddr; - __u32 daddr; -} my_iphdr_t; - - -typedef struct my_ethhdr { - unsigned char h_dest[6]; - unsigned char h_source[6]; - unsigned short h_proto; -} my_ethhdr_t; - /* * Function written by ek247. Exports console output from all domains upwards * to domain0, by stuffing it into a fake network packet. @@ -510,13 +475,13 @@ typedef struct my_ethhdr { int console_export(char *str, int len) { struct sk_buff *skb; - struct my_iphdr *iph = NULL; - struct my_udphdr *udph = NULL; - struct my_ethhdr *ethh = NULL; - int hdr_size = sizeof(struct my_iphdr) + sizeof(struct my_udphdr); + struct iphdr *iph = NULL; + struct udphdr *udph = NULL; + struct ethhdr *ethh = NULL; + int hdr_size = sizeof(struct iphdr) + sizeof(struct udphdr); u8 *skb_data; - skb = dev_alloc_skb(sizeof(struct my_ethhdr) + + skb = dev_alloc_skb(sizeof(struct ethhdr) + hdr_size + len + 20); if ( skb == NULL ) return 0; @@ -525,12 +490,12 @@ int console_export(char *str, int len) skb_reserve(skb, 2); /* Get a pointer to each header. */ - ethh = (struct my_ethhdr *) + ethh = (struct ethhdr *) (skb_data + (skb->data - skb->head)); - iph = (struct my_iphdr *)(ethh + 1); - udph = (struct my_udphdr *)(iph + 1); + iph = (struct iphdr *)(ethh + 1); + udph = (struct udphdr *)(iph + 1); - skb_reserve(skb, sizeof(struct my_ethhdr)); + skb_reserve(skb, sizeof(struct ethhdr)); skb_put(skb, hdr_size + len); /* Build IP header. */ @@ -544,12 +509,12 @@ int console_export(char *str, int len) iph->saddr = htonl(0xa9fefeff); /* 169.254.254.255 */ iph->tot_len = htons(hdr_size + len); iph->check = 0; - iph->check = compute_cksum((__u16 *)iph, sizeof(struct my_iphdr)/2); + iph->check = compute_cksum((__u16 *)iph, sizeof(struct iphdr)/2); /* Build UDP header. */ udph->source = htons(current->domain); udph->dest = htons(666); - udph->len = htons(sizeof(struct my_udphdr) + len); + udph->len = htons(sizeof(struct udphdr) + len); udph->check = 0; /* Build the UDP payload. */ diff --git a/xen/include/xeno/net_headers.h b/xen/include/xeno/net_headers.h new file mode 100644 index 0000000000..a90b201227 --- /dev/null +++ b/xen/include/xeno/net_headers.h @@ -0,0 +1,128 @@ +/* + * net_headers.h + * + * This is a compilation of various network headers, to facilitate + * access in Xen, which is generally quite simple and doesn't need + * all the bloat of extra defines and so on. + * + * Pretty much everything here is pulled from ip.h, tcp.h, and if_eth.h + * + * Reduced, congealed, and otherwise munged by akw. + * + * Original authors: + * + * Fred N. van Kempen, (ip.h, tcp.h, udp.h) + * + * (if_arp.h): + * Original taken from Berkeley UNIX 4.3, (c) UCB 1986-1988 + * Portions taken from the KA9Q/NOS (v2.00m PA0GRI) source. + * Ross Biro, + * Fred N. van Kempen, + * Florian La Roche, + * Jonathan Layes + * Arnaldo Carvalho de Melo ARPHRD_HWX25 + * + * Original legalese: + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#ifndef __NET_HEADERS_H__ +#define __NET_HEADERS_H__ + +#include +#include +#include + +/* from ip.h */ + +struct iphdr { +#if defined(__LITTLE_ENDIAN_BITFIELD) + __u8 ihl:4, + version:4; +#elif defined (__BIG_ENDIAN_BITFIELD) + __u8 version:4, + ihl:4; +#else +#error "Please fix " +#endif + __u8 tos; + __u16 tot_len; + __u16 id; + __u16 frag_off; + __u8 ttl; + __u8 protocol; + __u16 check; + __u32 saddr; + __u32 daddr; + /*The options start here. */ +}; + +/* from tcp.h */ + +struct tcphdr { + __u16 source; + __u16 dest; + __u32 seq; + __u32 ack_seq; +#if defined(__LITTLE_ENDIAN_BITFIELD) + __u16 res1:4, + doff:4, + fin:1, + syn:1, + rst:1, + psh:1, + ack:1, + urg:1, + ece:1, + cwr:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + __u16 doff:4, + res1:4, + cwr:1, + ece:1, + urg:1, + ack:1, + psh:1, + rst:1, + syn:1, + fin:1; +#else +#error "Adjust your defines" +#endif + __u16 window; + __u16 check; + __u16 urg_ptr; +}; + +/* From udp.h */ + +struct udphdr { + __u16 source; + __u16 dest; + __u16 len; + __u16 check; +}; + +/* from if_arp.h */ + +struct arphdr +{ + __u16 ar_hrd; /* format of hardware address */ + __u16 ar_pro; /* format of protocol address */ + __u8 ar_hln; /* length of hardware address */ + __u8 ar_pln; /* length of protocol address */ + __u16 ar_op; /* ARP opcode (command) */ + + /* This next bit is variable sized, and as coded only allows ETH-IPv4 */ + __u8 ar_sha[ETH_ALEN]; /* sender hardware address */ + __u32 ar_sip; /* sender IP address */ + __u8 ar_tha[ETH_ALEN]; /* target hardware address */ + __u32 ar_tip; /* target IP address */ +}; + + +#endif /* __NET_HEADERS_H__ */ -- 2.30.2